﻿using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;

namespace UIFrame
{
    /// <summary>
    /// 数字输入  TODO :重做
    /// </summary>
    public class InputNumItem : CommonItem
    {
        public int inputNum;
        //数字范围限制
        private int max = 9;
        private int min = 0;
        private Text NumberText;
        private Image background;

        public void SetRange(int min, int max)
        {
            this.min = min;
            this.max = max;
        }

        public void Awake()
        {
            NumberText = GetComponentInChildren<Text>();
            background = GetComponent<Image>();
        }

        /// <summary>
        /// 数字变化
        /// </summary>
        /// <param name="IsAdd">true就+1，false就-1 </param>
        public void AddNum(bool IsAdd)
        {
            if (IsAdd)
            {
                if (inputNum == max)
                    inputNum = min;
                else
                    inputNum++;
            }
            else
            {
                if (inputNum == min)
                    inputNum = max;
                else
                    inputNum--;
            }
            UpdateShow();
        }

        public void UpdateShow()
        {
            NumberText.text = inputNum.ToString();
        }
        //（密码*）隐藏显示
        public void Hide()
        {
            NumberText = GetComponentInChildren<Text>();
            NumberText.text = "*";
        }

        public void StartInput()
        {   
            background.color = Color.yellow;
        }
      

        public void EndInput()
        {
            background.color = new Color(0.08627451f, 0.4666667f, 0.7019608f, 1f);            
        }
    }
}